<template>
  <div class="photoInfo">
    <header>
      <h1 class="title">{{photoInfo.title}}</h1>
      <div class="btn-group">
        <span class="add-time">{{photoInfo.add_time}}</span>
        <span>点击{{photoInfo.click}}次</span>
      </div>
      <hr />
    </header>

    <!-- 内容区域 -->
    <div class="content">
      <div class="con2">
        <img v-for="(thum,index) in thums"
             :key="thum.id"
             :src="thum.src"
             @click="showImag(index)">
      </div>
      <p>{{photoInfo.content}}</p>
    </div>

    <!-- 评论区域 做渲染-->
    <Comment></Comment>

  </div>
</template>
<script>
import Comment from '@/components/Comment'
export default {
  data: () => ({
    id: 0,
    photoInfo: {},
    thums: []
  }),
  created () {
    this.id = this.$route.params.id
    this.getimageInfo()
    this.getthumimages()
  },
  methods: {
    async getimageInfo () {
      const {
        data: { status, message }
      } = await this.$axios.get('api/getimageInfo/' + this.id)
      if (status !== 0) this.$Toast(message)
      this.photoInfo = message
    },
    async getthumimages () {
      const {
        data: { status, message }
      } = await this.$axios.get('api/getthumimages/' + this.id)
      if (status !== 0) this.$Toast(message)
      console.log(message)
      this.thums = message
    },
    showImag (startPosition) {
      let images = []
      this.thums.forEach(item => {
        if (item.src) images.push(item.src)
      })
      this.$ImagePreview({
        images,
        startPosition
      })
    }
  },
  components: {
    Comment
  }
}
</script>
<style lang="less" scoped>
.photoInfo{
  padding: 0px 8px;
  header{
    h1{
      text-align: center;
    }
    .title{
      font-size: 16px;
      color:red;
    }
    .btn-group{
      font-size: 12px;
      display: flex;
      justify-content: space-between;
      .add-time{
        color: blue
      }
    }
  }
  .content{
    .con2{
      display: flex;
      justify-content: space-around;
      img{
      width: 110px;
      }
    }
  }
}
</style>
